package br.mikhas.container.factory;

/**
 * <p>
 * Defines a bean scope.
 * 
 * <p>
 * A scope defines the life-time of a resource. It means that a resource borns
 * and dies with its scope.
 * 
 * @author Mikhail Domanoski
 * 
 */
public interface Scope {

	/**
	 * Returns the name of the scope
	 */
	public String getName();

	/**
	 * Get an resource from its scope
	 * 
	 * @param name
	 *            The name of the resource
	 * @return The resource or <code>null</code> if it does not exists in the
	 *         scope
	 */
	public Object getResource(String name);

	/**
	 * Removes a resource from the scope
	 */
	public void removeResource(String name);

	/**
	 * Adds a new resource to the Scope
	 * 
	 * @param name
	 *            The name of the resource
	 * @param resource
	 *            The resource
	 */
	public void addResource(String name, Object resource);

	/**
	 * The key used to store the state of the scope
	 */
	public static final String SCOPE_STATE_KEY = "container::scope::state";

	public enum State {
		/**
		 * The scope state is idle.
		 * <p>
		 * No action is being taken by now.
		 */
		Idle,
		/**
		 * The scope is on initialization process
		 */
		Initializing,
		/**
		 * The scope is ready to use
		 */
		Ready,
		/**
		 * Scope is on destruction process
		 */
		Destruction
	}

	/**
	 * Gets the current scope state
	 * 
	 * @return
	 */
	public State getState();

	/**
	 * Sets the scope currenct state
	 * 
	 * @param state
	 */
	void setState(State state);
}
